export function getComment() {
  Valine({
    el: '#vcomments',
    appId: 'vJv21g92zHDNSyD60VsPJCXy-gzGzoHsz',
    appKey: '56MxoGN5xSqCvjVYjVWIxUqL',
    path: window.location.pathname,
    avatar: 'retro',
    placeholder: '昵称输入QQ号可自动补全信息；支持 Markdown',
    enableQQ: true,
    recordIP: true,
  })
  // 获取输入的昵称、邮箱、评论内容
  let nick = document.getElementsByName('nick')[0]
  let mail = document.getElementsByName('mail')[0]
  let textArea = document.getElementById('veditor')
  // 邮箱正则
  const regExp = /^[A-Za-z0-9]+([_\.][A-Za-z0-9]+)*@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,6}$/
  let btn = document.getElementsByClassName('vsubmit')[0]
  if (btn) {
    btn.addEventListener('click', async e => {
      let nickText = nick.value
      let mailText = mail.value
      let textDesc = textArea.value
      let isok = regExp.test(mailText)
      if (nickText.trim() === '') {
        this.$Message.warning('先输入昵称哦~~')
      } else if (mailText.trim() && !isok) {
        this.$Message.warning('邮箱格式不正确哦~~')
      } else if (textDesc.trim() === '') {
        this.$Message.warning('先输入评论哦~~')
      } else {
        btn.click()
      }
    })
  }
}